package com.example.neusoft.a16110100126yttordering.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.a16110100126yttordering.R;
import com.example.neusoft.a16110100126yttordering.activities.FoodInfoActivity;
import com.example.neusoft.a16110100126yttordering.bean.FoodInfo;
import com.example.neusoft.a16110100126yttordering.common.Constants;
import com.squareup.picasso.Picasso;

import java.util.List;

public class FoodListAdapter extends RecyclerViewAdapter<FoodListAdapter.ViewHolder> {
    public FoodListAdapter(Context context, List data,int layoutResource){
        super(context,data,layoutResource);

    }

    @Override
    public void onBindViewHolder(@NonNull FoodListAdapter.ViewHolder holder, int position) {
        final FoodInfo entity=(FoodInfo)data.get(position);
        holder.food_foodname.setText(entity.getFoodname());
        holder.food_price.setText(entity.getPrice()+"元");
        holder.food_intro.setText(entity.getIntro());
        if(!entity.getPic().equals("")){
            Picasso.get().load(Constants.BASE_URL+entity.getPic()).into(holder.food_pic);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context,FoodInfoActivity.class);
                intent.putExtra("id",entity.getFood_id());
                context.startActivity(intent);
            }
        });


    }
    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView food_pic;
        TextView food_foodname,food_price,food_intro;
//        ConstraintLayout food_container;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            food_foodname=itemView.findViewById(R.id.textView_item1);
            food_pic=itemView.findViewById(R.id.imageView_item1);
            food_price=itemView.findViewById(R.id.textView2_item1);
            food_intro=itemView.findViewById(R.id.textView1_item1);
            System.out.println("-----yttttttttt----------");
//            food_container=(ConstraintLayout)itemView.findViewById(R.id.food_container);
        }
    }

}
